// Copyright (C) 1953-2022 NUDT
// Verilog module name - traffic_rate_limit
// Version: V4.0.0.20220525
// Created:
//         by - fenglin 
////////////////////////////////////////////////////////////////////////////
// Description:
//         judge outport of standard ethernet packet
///////////////////////////////////////////////////////////////////////////

`timescale 1ns/1ps

module traffic_rate_limit
#(
    parameter clk_period = {8'd8,41'h0}//8ns
)
(
        i_clk                       ,  
        i_rst_n                     ,
        
        iv_addr                     ,         
        iv_wdata                    ,         
        i_wr                        ,      
        i_rd                        ,                                    
        o_wr                        ,      
        ov_addr                     ,      
        ov_rdata                    ,          
                        
        iv_desp                     ,
		i_desp_wr                   ,                                   
        ov_desp                     ,
		o_desp_wr                    
);

// I/O
// clk & rst
input                   i_clk;                   //125Mhz
input                   i_rst_n;

input       [18:0]      iv_addr;                         
input       [31:0]      iv_wdata;                        
input                   i_wr;         
input                   i_rd;         
output                  o_wr              ;
output     [18:0]       ov_addr           ;
output     [31:0]       ov_rdata          ;
// pkt_bufid and pkt_type and outport from lookup_table
input      [87:0]       iv_desp;
input                   i_desp_wr;
// pkt_bufid and pkt_type to p0
output     [87:0]       ov_desp;
output                  o_desp_wr;
// 
wire       [15:0]       wv_token_bucket_size;
wire       [15:0]       wv_add_tokens_num_perround;
command_parse_and_encapsulate_trl command_parse_and_encapsulate_trl_inst
(
        .i_clk                       (i_clk              ),       
        .i_rst_n                     (i_rst_n            ),      

        .iv_addr                     (iv_addr            ),         
        .iv_wdata                    (iv_wdata           ),         
        .i_wr                        (i_wr               ),      
        .i_rd                        (i_rd               ),        

        .o_wr                        (o_wr               ),      
        .ov_addr                     (ov_addr            ),      
        .ov_rdata                    (ov_rdata           ),      

        .ov_token_bucket_size        (wv_token_bucket_size       ),      
        .ov_add_tokens_num_perround  (wv_add_tokens_num_perround )           
); 

token_bucket_algorithm 
#(
.clk_period(clk_period)
)
token_bucket_algorithm_inst(
        .i_clk                       (i_clk              ),       
        .i_rst_n                     (i_rst_n            ),      

        .iv_desp                     (iv_desp             ),         
        .i_desp_wr                   (i_desp_wr           ),            

        .ov_desp                     (ov_desp             ),      
        .o_desp_wr                   (o_desp_wr           ),      
        
        .iv_token_bucket_size        (wv_token_bucket_size       ),      
        .iv_add_tokens_num_perround  (wv_add_tokens_num_perround )  
);

endmodule